package ewgenius.xube.engine.graphics.gui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import ewgenius.xube.XubeEngine;

public class GuiCollection extends ArrayList<Gui> {

	public boolean addInOrder(Gui gui) {
		gui.zindex = 0;
		gui.container = this;

		for (Gui g : this)
			g.zindex++;
		this.add(gui);
		organize();
		return true;
	}

	public void push() {
		int i = 0;
		for (int j = 0; j <= this.size(); j++, i++) {
			Gui g = this.get(j);
			if (g.zindex == -1) {
				g.zindex = 0;
				break;
			}
		}
		for (int j = i; j < this.size(); j++) {
			Gui g = this.get(j);
			XubeEngine.traceConsole(g.zindex);
			g.zindex++;
		}
		Collections.sort(this);
	}

	public void organize() {
		XubeEngine.traceConsole('\n');
		for (Gui g : this) {
			XubeEngine.traceConsole(g.zindex);
		}
		Collections.sort(this);
	}

}
